import { GetParams } from '@/types/global'
import setupMock, { successResponseWrap } from '@/utils/setup-mock'
import dayjs from 'dayjs'
import Mock from 'mockjs'
import qs from 'query-string'

let list = [
  {
    id: 1,
    title: '123',
  },
]
setupMock({
  setup() {
    Mock.mock(new RegExp('/api/content-data'), () => {
      const presetData = [58, 81, 53, 90, 64, 88, 49, 79]
      const getLineData = () => {
        const count = 8
        return new Array(count).fill(0).map((el, idx) => ({
          x: dayjs()
            .day(idx - 2)
            .format('YYYY-MM-DD'),
          y: presetData[idx],
        }))
      }
      return successResponseWrap([...getLineData()])
    })
    Mock.mock(new RegExp('/api/popular/list'), (params: GetParams) => {
      const { type = 'text' } = qs.parseUrl(params.url).query
      if (type === 'image') {
        return successResponseWrap([...list])
      }
      if (type === 'video') {
        return successResponseWrap([...list])
      }
      return successResponseWrap([...list])
    })
  },
})
